package com.woniu.cms.goods.core.controller;


import com.woniu.cms.goods.core.dto.GetbillDto;
import com.woniu.cms.goods.core.entity.GoodsGetbill;
import com.woniu.cms.goods.core.entity.GoodsGetbillMaterial;
import com.woniu.cms.goods.core.service.IGoodsGetbillService;
import com.woniu.cms.goods.core.vo.GetbillVo;
import com.woniu.common.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 入库单表 前端控制器
 * </p>
 *
 * @author romantic sheep
 * @since 2022-09-16
 */
@RestController
@Api(tags = "入库单模块")
@RequestMapping("/goods-getbill")
public class GoodsGetbillController {

    @Autowired
    private IGoodsGetbillService getbillService;

    /*
    * 入库单新增
    * @getbill，入库单添加对象
    * @list，入库单对应的材料详情
    * */
    @PostMapping("insert")
    @ApiOperation("添加入库单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "getbillDto",value = "入库单添加对象,入库单对应的材料详情")
    })
    public Result addGetbill(@RequestBody GetbillDto getbillDto){
        GoodsGetbill getbill = getbillDto.getGetbill();
        List<GoodsGetbillMaterial> list = getbillDto.getList();
        Result result=getbillService.addGetbill(getbill,list);
        return result;
    }
    /*
     * 入库单删除
     * @id，需删除对象的id
     * @status，需删除对象的状态
     * */
    @DeleteMapping("delete")
    @ApiOperation("删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "需删除对象的id"),
            @ApiImplicitParam(name = "status",value = "需删除对象的状态")
    })
    public Result deleteGetbill(Integer id,Integer status){
        Result result=getbillService.deleteGetbill(id,status);
        return result;
    }
    /*
     * 入库单修改
     * @getbill，需修改的入库单对象
     * @list，需修改的入库单对应的材料明细
     * */
    @PutMapping("update")
    @ApiOperation("修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "getbillDto",value = "需修改的入库单对象,需修改的入库单对应的材料明细")
    })
    public Result updateGetbill(@RequestBody GetbillDto getbillDto){
        GoodsGetbill getbill = getbillDto.getGetbill();
        List<GoodsGetbillMaterial> list = getbillDto.getList();
        Result result=getbillService.updateGetbill(getbill,list);
        return result;
    }
    /*
     * 入库单提交
     * @getbill，需提交的入库单对象
     * @list，需提交的入库单对应的材料明细
     * */
    @PutMapping("commit")
    @ApiOperation("提交")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "getbillDto",value = "需提交的入库单对象,需提交的入库单对应的材料明细")
    })
    public Result commitGetbill(@RequestBody GetbillDto getbillDto){
        GoodsGetbill getbill = getbillDto.getGetbill();
        List<GoodsGetbillMaterial> list = getbillDto.getList();
        Result result=getbillService.commitGetbill(getbill,list);
        return result;
    }
}

